/**
 * Copyright:Copyright(c)2014-2015
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.services.manage.spec.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import shop.core.ServicesManager;
import shop.services.manage.spec.SpecService;
import shop.services.manage.spec.bean.Spec;
import shop.services.manage.spec.dao.SpecDao;

import javax.annotation.Resource;
import java.util.List;


/**
 * @类名称：SpecServiceImpl
 * @创建人：Ltz
 * @创建时间：2017-09-20 下午15:51:23
 * @版本号：1.0
 * @描述：
 */
@Service("specServiceManage")
public class SpecServiceImpl extends ServicesManager<Spec, SpecDao> implements
SpecService {
    @Resource(name = "specDaoManage")
    @Override
    public void setDao(SpecDao specDao) {
    this.dao = specDao;
    }

    public int deleteByCom(String specCombination) {
        return dao.deleteByCom(specCombination);
    }

    public Spec selectByCom(String id) {
        return dao.selectByCom(id);
    }

    //通过商品ID获取对应的规格
    public List<Spec> selectByProductID(int e) {
        return dao.selectByProductID(e);
    }

    public int deleteByPID(int id) {
        return dao.deleteByPID(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    public int deletesByPID(String[] ids) {
        if (ids == null || ids.length == 0) {
            throw new NullPointerException("id不能全为空！");
        }

        for (int i = 0; i < ids.length; i++) {
            if(StringUtils.isBlank(ids[i])){
                throw new NullPointerException("id不能为空！");
            }
            dao.deleteByPID(Integer.parseInt(ids[i]));
        }
        return 0;
    }
}

